package org.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Database {
	Connection conn=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	String divStr="com.mysql.jdbc.Driver";
	String url="jdbc:mysql://127.0.0.1:3306/test?user=root&password=123";
	public Connection getConn(){
		try {
			Class.forName(divStr);
			conn= DriverManager.getConnection(url);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}
	public void closConn(Connection myConn){
		conn=myConn;
		try {
			if(conn!=null){
			conn.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void closConn(Connection myConn,PreparedStatement myPs){
		conn=myConn;
		ps=myPs;
		try {
			if(conn!=null&&ps!=null){
			ps.close();
			conn.close();
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void closConn(Connection myConn,PreparedStatement myPs,ResultSet myRs){
		conn=myConn;
		ps=myPs;
		rs=myRs;
		try {
			if(conn!=null&&ps!=null&&rs!=null){
			rs.close();
			ps.close();
			conn.close();
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
